package com.lancoo.cvas.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lancoo.cvas.entity.ClassInfo;
import com.lancoo.cvas.entity.Schedule;
import com.lancoo.cvas.entity.ScheduleConflictInfo;
import com.lancoo.cvas.entity.Student;
import com.lancoo.cvas.exception.CapacityException;
import com.lancoo.cvas.pojo.common.PageInfo;
import com.lancoo.cvas.pojo.dto.*;
import com.lancoo.cvas.pojo.vo.*;

import java.io.IOException;
import java.util.List;

/**
 * 课表
 *
 * @author liufeng
 * @email 1037383243@qq.com
 * @date 2023-12-04 11:54:00
 */
public interface ScheduleService extends IService<Schedule> {


    PageInfo<TeachingClassScheduleArrangeDto> getTeachingClassCoursePage(Integer taskId, Page<TeachingClassCourseDto> page, Integer state, String gradeId, String majorId, String keyword);

    PageInfo<TeachingClassCourseDto> getTeachingClassCourse(Integer taskId, Page<TeachingClassCourseDto> page, Integer state, String gradeId, String majorId, String keyword);

    PageInfo<TeachingClassSegmentDto> getTeachingClassSegmentPage(Integer taskId, Page<TeachingClassSegmentDto> page, String gradeId, String majorId, String type, String keyword);

    /**
     * @param currentPage:
     * @param pageSize:
     * @param taskId:
     * @param weeks:
     * @param timeCodes:
     * @param roomId:
     * @param teachingClass:
     * @Description: 获取调整场地节次 列表
     * @Author: liufeng
     * @Date: 2023/12/12 15:12
     * @return:
     */
    PageInfo<VenueSessionVo> getVenueSession(Integer currentPage, Integer pageSize, Integer taskId, String weeks, String timeCodes, Integer buildingId, Long roomId, String keyword, ArrangeTeachingClassDto teachingClass) throws CapacityException;

    List<ArrangeRoomRuleDto> getArrangeRoomProhibit(Integer taskId, String schoolId, String term, String campusId);

    List<ArrangeTeacherRuleDto> getArrangeTeacherTime(Integer taskId, String schoolId, String termId);

    List<ArrangeCourseRuleDto> getArrangeCourseProhibit(Integer taskId);

    List<ArrangeClassRuleDto> getArrangeClassProhibit(Integer taskId);

    List<ArrangeTeachingClassRuleDto> getArrangeTeachingClassProhibit(Integer taskId);

    List<ArrangePeriod> getArrangeTimeCode(Integer taskId, String schoolId, String termId);

    List<ArrangeScheduleDto> getLockSchedule(Integer taskId, String campusId, Integer isLocked, Integer roomType);

    List<ArrangeScheduleDto> getScheduleListByTeachingClassIds(Integer taskId, String campusId, List<Long> teachingClassIds);

    /**
     * 调整周次
     *
     * @param updateSchedule
     * @param addSchedule
     * @param teachingClassId
     * @return
     */
    List<ScheduleDto> updateVenueSession(List<Schedule> updateSchedule, List<Schedule> addSchedule, Long teachingClassId, Integer hourType);

    /**
     * 更新教学班排课状态
     *
     * @param arrangeTeachingClassUpdates
     */
    void updateScheduleState(List<ArrangeTeachingClassUpdate> arrangeTeachingClassUpdates);

    /**
     * @param taskId:
     * @Description: 自动排课 返回冲突
     * @Author: liufeng
     * @Date: 2023/12/12 17:18
     * @return:
     */
    List<ScheduleConflictInfo> autoArrangement(Integer taskId);


    /**
     * @param taskId:
     * @param schoolId:
     * @param term:
     * @Description: 统计需要新建的教室
     * @Author: liufeng
     * @Date: 2024/1/9 11:37
     * @return:
     */
    RoomRequire requireRoom(Integer taskId, String schoolId, String term, Integer roomType);

    /**
     * @param taskId:
     * @Description: 排课进度
     * @Author: liufeng
     * @Date: 2023/12/15 14:47
     * @return:
     */
    StatisticsArrange getPublishStatisticsArrange(Integer taskId, String schoolId);
    StatisticsArrange getPublishStatisticsArrangeV2(Integer taskId, String schoolId);


    /**
     * 获取教学班数据.未锁定教学班
     *
     * @param taskId
     * @param campusId 学院id 传null获取全部
     * @return
     */
    List<ArrangeTeachingClassDto> getTeachingClassDate(Integer taskId, String campusId);

    /**
     * 存储每轮排课的课程信息，即课表信息
     *
     * @param schedules
     */
    void addBathSchedule(Integer taskId, List<Schedule> schedules);

    /**
     * 存储每轮排课的冲突信息
     *
     * @param scheduleConflicts
     */
    void addBatchScheduleConflict(Integer taskId, List<ScheduleConflictInfo> scheduleConflicts, List<Long> roomIds);


    List<ScheduleConflictInfo> getScheduleConflictInfo(Long teachingClassId, Integer hourType);

    Boolean updateLock(Integer taskId, Integer isLocked, LockDto locks);

    Boolean allNormalLocal(Integer taskId);

    Boolean unlockedNormal(Integer taskId);

    Integer isLockedNormal(Integer taskId);


    String courseToExcel(Integer taskId, Integer scheduleState, String gradeId, String gradeName, String majorId, String majorName, String keyword);

    /**
     * @param taskId:
     * @param teacherId:
     * @Description: 教师课表
     * @Author: liufeng
     * @Date: 2023/12/19 18:56
     * @return:
     */
    List<TeachingClassWeekScheduleDto> getTeacherSchedule(Integer taskId, Long teacherId, String schoolId, String term);

    List<TeachingClassWeekScheduleDto> getClassSchedule(Integer taskId, Long classId);

    List<TeachingClassWeekScheduleDto> getStudentSchedule(Integer taskId, Long classId);

    List<TeachingClassWeekScheduleDto> getRoomSchedule(Integer taskId, Long roomId, String schoolId, String term);

    List<TeachingClassWeekScheduleDto> getTeachingClassSchedule(Integer taskId, Long teachingClassId);

    UnionSchedule getUnionSchedule(Integer taskId, Long id, Integer module, String schoolId, String term, String timeCode);

    List<Schedule> generateTeachingClassUnit(Integer taskId, List<GenerateTeachingClassUnitInput> generateTeachingClassUnits);

    Boolean allToTeachingClassUnit(Integer taskId);

    void removeSchedule(Integer taskId, List<Schedule> scheduleList);

    void subSchedule(Integer taskId, SubScheduleDto subScheduleDto);

    PageInfo<ClassInfo> getAllClassSchedule(Integer taskId, String schoolId, String term, String gradeId, Long classId, String keyword, Integer currentPage, Integer pageSize);

    PageInfo<AllScheduleVo> getAllTeacherSchedule(Integer taskId, String schoolId, String keyword, String term, Integer currentPage, Integer pageSize);

    PageInfo<AllScheduleVo> getAllRoomSchedule(Integer taskId, String schoolId, String term, String campusId, Integer buildingId, String keyword, Integer currentPage, Integer pageSize);

    PageInfo<AllScheduleVo> getAllTeachingClassSchedule(Integer taskId, String schoolId, String term, Long courseId, String keyword, Integer currentPage, Integer pageSize);
    /*
    导出excele
     */

    String classScheduleToExcel(Integer taskId, Long classId);

    String teacherScheduleToExcel(Integer taskId, Long teacherId);

    String roomScheduleToExcel(Integer taskId, Long roomId);

    String teachingClassScheduleToExcel(Integer taskId, Long teachingClassId);

    /**
     * 导出总表
     *
     * @param taskId
     * @param scheduleType
     * @param scheduleType 1:教室 2:教师 3:行政班 4:教学班
     */
    String summaryScheduleToExcel(Integer taskId, Integer scheduleType) throws IOException;

    /**
     * @param taskId:
     * @Description: 课表同步到基础平台 数据处理
     * @Author: liufeng
     * @Date: 2023/12/29 9:16
     * @return:
     */
    String allScheduleToExcel(Integer taskId);

    String segmentToExcel(Integer taskId, String gradeId, String majorId, String courseTypeId, String keyword);


    int[] classStatistics(Integer taskId, String schoolId, String term);

    /**
     * =================================================================================================================
     * 根据学生获取对应的课表
     * @param taskId
     * @param studentId
     * @return
     */
    List<TeachingClassWeekScheduleDto> getScheduleByClassId(Integer taskId, Long studentId,List<Long> teachingClassIds);


    List<ArrangeTeachingClassRuleDto> removeProhibitFromCourse(Integer taskId, String schoolId, String termId, List<ArrangeTeachingClassRuleDto> teachingClassRuleList);

    Boolean checkByStudentId(Integer taskId, CheckByStudentIdDTO checkByStudentIdDTO);

    List<Student> checkByStudentIdBatch(Integer taskId, CheckByStudentIdBatchDTO checkByStudentIdBatchDTO);
    void fillConflict(List<ScheduleConflictInfo> scheduleConflictInfos);
}

